home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: kremser@sbox.tu-graz.ac.at (Herbert Kremser)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: const pointer confusion...
- Followup-To: comp.lang.c,comp.lang.c.moderated
- Date: 25 Mar 1996 06:27:04 -0600
- Organization: Graz University of Technology, Austria
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4j63eo$3lo@solutions.solon.com>
- References: <4j06gm$7oa@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- Reed R. Mangino (mangino@planet.net) wrote:
- : Could someone please straighten me out on this:
- :
- : 1) const int *p = 10;
- : p is a constant pointer to an int, right? While p can be made to
- : point to something else, *p can never be assigned to, right?
-
- correct
- btw, the "= 10" part will cause undefined, and most probably silly, behavior.
-
- :
- : 2) int *const p;
- : p is a pointer to an integer. *p can be assigned to, but p can
- : never be made to point to another address in memory, right?
-
- correct
-
- :
- : 3) int const *p;
- : What the heck is this? I can't find anything like this in my
- : books, but my compiler thinks everything is hunky doory!???
-
- it's the same as const int *p;
-
- const refers always to the thing on it's left side. If there is nothing
- further left, it refers to the leftmost thing.
-
- Therefore i prefer
-
- int const i = 10;
- over
- const int i = 10;
-
- most of the time. :-)
-
-
- Herbert
- --
- Herbert Kremser | "On the Internet,
- kremser@flinux.tu-graz.ac.at | nobody knows
- kremser@sbox.tu-graz.ac.at | you're a dog."
-